<template>
  <div style="position: relative; height: 100%">
    <!--  巡检报表  -->
    <div class="top">
      <div class="l">
        <div style="display: flex; align-items: center">
          <span style="display: inline-block; color: #366">网关名</span>
          <el-input v-model="gatewayName" placeholder="请输入网关名" style="width: 200px; margin-left: 10px;" />
          <el-date-picker
              v-model="logTime"
              type="datetimerange"
              range-separator="~"
              start-placeholder="起始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD HH:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
              style="width: 400px; margin-left: 10px;"
          />
          <div class="def-btn" style="margin-left: 10px; margin-right: 30px" @click="searchHandle">搜索</div>
        </div>
      </div>
<!--      <div class="r">
        <div class="sure-btn down-btn" @click="downLoadExcel">导出</div>
      </div>-->
    </div>
    <div style="height: calc(100% - 120px)">
      <base-table :pagination="pagination"
                  @currentChange="currentChange">
        <el-table :data="tableData" stripe border
                  :cell-style="{ textAlign: 'center' }"
                  :header-cell-style="{ textAlign: 'center' }"
                  header-row-class-name="headerRow"
                  class="lamp-table"
                  style="width: 100%; height: calc(100% - 50px); overflow: auto">
          <el-table-column type="index" width="150" label="序号" #default="scope">
            {{ scope.$index < 9 ? '0' + (scope.$index + 1) : scope.$index + 1 }}
          </el-table-column>
          <el-table-column prop="inspectionGateway" label="网关名" width="300" />
          <el-table-column prop="inspectionLight" label="巡检灯具" width="160" />
          <el-table-column prop="inspectionResultTxt" label="巡检结果" #default="scope">
            <span @click="viewTable(item, scope.row)" v-for="item in scope.row.inspectionResultTxt">{{ item }}</span>
          </el-table-column>
          <el-table-column prop="createTime" label="巡检时间" width="220" />
        </el-table>
      </base-table>
    </div>

    <inspection-report-table ref="inspectionReportTable"></inspection-report-table>

  </div>
</template>

<script>
import { lampeInspectionLogs} from "../../router/api.js";
import {downBlobFile, downloadFile} from "../../util/index.js";
import BaseTable from "../../components/baseTable.vue";
import InspectionReportTable from "./modules/inspectionReportTable.vue";
export default {
  name: "inspectionReport",
  components: {InspectionReportTable, BaseTable },
  data() {
    return {
      gatewayName: '',
      pagination: {
        page: 1,
        size: 17,
        total: 0,
      },
      tableData: [],
      logTime: []
    }
  },
  created() {
    this.init()
  },
  methods: {
    async init() {
      let res = await lampeInspectionLogs({
        startTimeStr: this.logTime[0],
        endTimeStr: this.logTime[1],
        gatewayName: this.gatewayName,
        page: this.pagination.page,
        size: this.pagination.size,
      })
      if (res.data.code == 200) {
        if ( res.data.data && res.data.data.records) {
          this.tableData = res.data.data.records;
          this.pagination.total = res.data.data.total;

          this.tableData.forEach(opt => {
            opt['inspectionResultTxt'] = opt['inspectionResult'].split(',')
          })

        }
      } else {
        this.tableData = [];
        this.pagination.total = 0;
        // this.$message.warning(res.data.msg)
      }
    },
    downLoadExcel() {
      if(!this.logTime.length) return;
      downBlobFile('/api/opt/user/exportLogsByTime',{
        startTime: this.logTime[0],
        endTime: this.logTime[1],
      },`日志报表.xlsx`,'GET')
    },
    currentChange(val) {
      this.pagination.page = val;
      this.init();
    },
    searchHandle(){
      this.pagination.page = 1;
      this.init();
    },
    viewTable(val, row){
      this.$refs.inspectionReportTable.show(val,row)
    }
  }
}
</script>

<style scoped lang="scss">
.down-btn:before {
  content: "\e60d";
}

.lamp-table{
  height: 100%;
}
.top {
  display: flex;
  justify-content: space-between;
  margin: 0 auto 20px;

  .l {
    display: flex;
    align-items: center;
  }

  .r {
    display: flex;

    .def-btn {
      width: initial;
      padding: 0 14px;
    }
  }
}
</style>
<style>
.headerRow {
  background: linear-gradient(to right, #6B92F0, #76D0FF) !important;
}

.el-table th.el-table__cell {
  background-color: transparent;
  color: #fff;
}

.el-table thead.is-group th.el-table__cell {
  background-color: transparent;
  color: #fff;
}
</style>
